﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FineSoft.Models
{
	public class ConfigDictionary : System.Collections.Generic.IDictionary<string, Object>, System.Runtime.Serialization.ISerializable
	{
		private readonly System.Collections.Generic.Dictionary<string, Object> Dictionary = new Dictionary<string, Object>();


		#region IDictionary<string,Object> 成员

		public void Add(string key, Object value)
		{
			this.Dictionary.Add(key, value);
		}

		public bool ContainsKey(string key)
		{
			return this.Dictionary.ContainsKey(key);
		}

		public ICollection<string> Keys
		{
			get
			{
				return this.Dictionary.Keys;
			}
		}

		public bool Remove(string key)
		{
			return this.Dictionary.Remove(key);
		}

		public bool TryGetValue(string key, out Object value)
		{
			return this.Dictionary.TryGetValue(key, out value);
		}

		public ICollection<Object> Values
		{
			get
			{
				return this.Dictionary.Values;
			}
		}

		public Object this[string key]
		{
			get
			{
				Object value;
				this.TryGetValue(key, out value);
				return value;
			}
			set
			{
				this.Dictionary[key] = value;
			}
		}

		#endregion

		#region ICollection<KeyValuePair<string,Object>> 成员

		public void Add(KeyValuePair<string, Object> item)
		{
			this.Dictionary.Add(item.Key, item.Value);
		}

		public void Clear()
		{
			this.Dictionary.Clear();
		}

		public bool Contains(KeyValuePair<string, Object> item)
		{
			return this[item.Key] == item.Value;
		}

		public void CopyTo(KeyValuePair<string, Object>[] array, int arrayIndex)
		{
			System.Array.Copy(this.ToArray(), 0, array, arrayIndex, this.Keys.Count);
		}

		public int Count
		{
			get
			{
				return this.Dictionary.Keys.Count;
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public bool Remove(KeyValuePair<string, Object> item)
		{
			return this.Remove(item.Key);
		}

		#endregion

		#region IEnumerable<KeyValuePair<string,Object>> 成员

		public IEnumerator<KeyValuePair<string, Object>> GetEnumerator()
		{
			return this.Dictionary.GetEnumerator();
		}

		#endregion

		#region IEnumerable 成员

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return this.Dictionary.GetEnumerator();
		}

		#endregion

		public ConfigDictionary()
		{
		}

		#region ISerializable 成员

		public ConfigDictionary(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			this.Dictionary = (Dictionary<string, Object>)info.GetValue("Dictionary", typeof(Dictionary<string, Object>));
		}

		void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			info.AddValue("Dictionary", this.Dictionary);
		}

		#endregion
	}
}